package com.fang.common.util;

import com.fang.common.common.CommonResult;
import com.fang.common.common.ResultCode;
import com.fang.common.exception.ExceptionCode;
import com.fang.common.exception.NetworkDiskException;

/**
 * @author Bernie_fang
 * @Description:
 * @create 2024/10/2 22:51
 **/
public class CommonResultUtil {

    public static <T> CommonResult<T> success() {
        return new CommonResult<T>(ExceptionCode.CommonCode.SUCCESS.getCode(), ExceptionCode.CommonCode.SUCCESS.getMessage(), null);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(ExceptionCode.CommonCode.SUCCESS.getCode(), ExceptionCode.CommonCode.SUCCESS.getMessage(), data);
    }

    public static <T> CommonResult<T> success(String message, T data) {
        return new CommonResult<T>(ExceptionCode.CommonCode.SUCCESS.getCode(), message, data);
    }

    public static <T> CommonResult<T> failed() {
        return new CommonResult<T>(ExceptionCode.CommonCode.SYSTEM_BUSY.getCode(), ExceptionCode.CommonCode.SYSTEM_BUSY.getMessage(), null);
    }

    public static <T> CommonResult<T> failed(String code, String message) {
        return new CommonResult<T>(code, message, null);
    }

    public static <T> CommonResult<T> failed(NetworkDiskException exception) {
        return new CommonResult<T>(exception.getErrorCode(), exception.getMessage(), null);
    }

    public static <T> CommonResult<T> failed(ResultCode resultCodeMsg) {
        return new CommonResult<T>(resultCodeMsg.getCode(), resultCodeMsg.getMessage(), null);
    }

}
